package com.qo.qsdk.ui.base;

import android.app.Activity;
import android.graphics.Color;
import android.os.Handler;
import android.text.InputType;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;

import com.qo.qsdk.model.SDKInfoModel;
import com.qo.qsdk.model.UserModel;
import com.qo.qsdk.ui.QSDKListener;
import com.qo.qsdk.utils.DynamicUtils;
import com.qo.qsdk.utils.Language;
import com.qo.qsdk.utils.PwdManager;
import com.qo.qsdk.utils.QSDKHelper;

import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE;

import com.qo.qsdk.ui.base.third.Px7TextView;
import com.qo.qsdk.ui.base.third.Px9TextView;
import com.qo.qsdk.ui.base.third.Px9EditText;
import com.qo.qsdk.ui.base.third.StrokeTextView;
import com.qo.qsdk.ui.base.third.StrokeTextViewY;
public class PwdView{

    private StrokeTextViewY mPwdLeft, mPwdRight;
    private Px9TextView mPwdTime;
    private Activity mActivity;

    private QSDKListener mIAccountListener;

    public PwdView(Activity mActivity, QSDKListener iAccountListener) {
        this.mIAccountListener = iAccountListener;
        this.mActivity = mActivity;
        this.mActivity.setContentView(DynamicUtils.layout(this.mActivity, "qsdk_pwd"));
        init(mActivity);
    }

    private void init(Activity v) {

        mPwdLeft = v.findViewById(DynamicUtils.id(mActivity, "pwdLeft"));
        mPwdLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v2) {
                if (mIAccountListener != null) mIAccountListener.onPwdAgain();
                hide(v);
            }
        });
        mPwdRight = v.findViewById(DynamicUtils.id(mActivity, "pwdRight"));
        mPwdRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v2) {
                if (mIAccountListener != null) mIAccountListener.onPwdService();
                hide(v);
            }
        });
        mPwdTime = v.findViewById(DynamicUtils.id(mActivity, "pwdTime"));

        v.findViewById(DynamicUtils.id(mActivity, "pwdClose")).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v2) {
                if (mIAccountListener != null) mIAccountListener.onPwdClose();
                hide(v);
            }
        });

        refresh();
    }

    Handler handler=new Handler();
    Runnable runnable=new Runnable(){
        @Override
        public void run() {
            Log.e("qsdk", "---------");
            if (mPwdTime != null) {
                String t = PwdManager.getInstance().displayTime();
                if (t.length() > 0) {
                    mPwdTime.setText("(" + t + ")");
                }else{
                    mPwdTime.setText("");
                }
            }
            handler.postDelayed(this, 1000);
        }
    };
    public void show(Activity activity) {
        handler.postDelayed(runnable, 1000);
    }

    public void hide(Activity activity) {
        handler.removeCallbacks(runnable);
    }

    private void refresh() {
        mPwdLeft.setText(Language.Pwd_Btn_L.toString());
        mPwdRight.setText(Language.Pwd_Btn_R.toString());
    }


}
